package site.zhouinfo.designpattern.guanchazhemoshi.my;

import java.util.ArrayList;
import java.util.List;

/**
 * 报纸 被观察者
 *
 * @author zhou
 * @create 2017-04-06 17:41
 * @email zhouinfo@qq.com
 */
public class MyNewspaper {

    private String content;
    private List<MyObserver> readerList = new ArrayList<MyObserver>();

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void attach(MyObserver myObserver) {
        readerList.add(myObserver);
    }


    public void notifyObservers(String content) {
        this.content = content;
        for (MyObserver myObserver : readerList) {
            myObserver.update(content);
        }
    }
}
